package com.yiwei.jmx.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.yiwei.jmx.R;
import com.yiwei.jmx.activity.WebViewActivity;
import com.yiwei.jmx.api.model.ArticleNewsModel;
import com.yiwei.jmx.util.DateTime;

import butterknife.BindView;
import butterknife.ButterKnife;


/**
 * Created by xsooy-pc on 2017/10/23.
 */

public class RiskNewsAdapter extends ItemAdapter<ArticleNewsModel.DataBean, RiskNewsAdapter.DefaultHolder> {


    private Context context;

    public RiskNewsAdapter(Context context) {
        super(context);
        this.context = context;
    }

    @Override
    public DefaultHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new DefaultHolder(inflate(R.layout.item_risk_news, parent));
    }

    @Override
    public void onBindViewHolder(DefaultHolder holder, int position) {
        ArticleNewsModel.DataBean item = getItem(position);
        Glide.with(context).load(item.image).into(holder.imgIcon);
        holder.txtNum.setText(item.pv);
        holder.txtTitle.setText(item.title);
        holder.txtTime.setText(item.created_at);
        holder.layoutTotal.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, WebViewActivity.class);
                intent.putExtra("title", item.title);
                intent.putExtra("url", item.link_url);
                context.startActivity(intent);
            }
        });
    }

    class DefaultHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.img_icon)
        ImageView imgIcon;
        @BindView(R.id.txt_title)
        TextView txtTitle;
        @BindView(R.id.txt_num)
        TextView txtNum;
        @BindView(R.id.txt_time)
        TextView txtTime;
        @BindView(R.id.layout_total)
        RelativeLayout layoutTotal;

        public DefaultHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    private OnChooseListener onChooseListener;

    public void setOnChooseListener(OnChooseListener onChooseListener) {
        this.onChooseListener = onChooseListener;
    }

    public interface OnChooseListener {
        void onSuccess();
    }
}
